#include "Message.ServerMessage.h"
#include "Message.NotificationMessage.h"
#include "Message.RequestResponse.h"

namespace AlgoTrading
{
	namespace Messages
	{

		ServerMessage::ServerMessage(std::auto_ptr<PBServerMessage>& message)
			: serverMessage(message)
		{
		}

		ServerMessage::~ServerMessage(void)
		{
		}

		void ServerMessage::Serialize(std::ostream& ostream) const
		{
			serverMessage->SerializeToOstream(&ostream);
		}

		std::auto_ptr<ServerMessage> ServerMessage::Deserialize(std::istream& istream)
		{
			std::auto_ptr<PBServerMessage> serverMessage(new PBServerMessage());
			serverMessage->ParseFromIstream(&istream);

			switch(serverMessage->type())
			{
				case PBServerMessage_Type_PBNotification:
					return NotificationMessage::Deserialize(serverMessage);
					break;
				case PBServerMessage_Type_PBRequestResponse:
					return RequestResponse::Deserialize(serverMessage);
					break;
			}

			return std::auto_ptr<ServerMessage>(0);
		}

		/*ServerMessage::ServerMessageType ServerMessage::GetServerMessageType()
		{
			switch(serverMessage->type())
			{
				case PBServerMessage_Type_PBNotification:
					return NOTIFICATION_MESSAGE;
				case PBServerMessage_Type_PBRequestResponse:
					return REQUEST_RESPONSE;
			}
			return REQUEST_RESPONSE;
		}*/
	}
}